package com.yunkaweilai.android.view;

import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.Drawable;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.yunkaweilai.android.R;


/**
 * Created by Administrator on 2017/4/14 0014.
 */

public class LoadingView extends LinearLayout {
    public LoadingView(Context context) {
        super(context);
    }

    public LoadingView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public LoadingView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        View view = LayoutInflater.from(getContext()).inflate(R.layout.view_my_loading,null);
        addView(view);
        ImageView idImg = (ImageView) view.findViewById(R.id.id_img);

        AnimationDrawable anim = new AnimationDrawable();
        for (int i = 1; i <= 6; i++) {
            int id = getResources().getIdentifier("icon_" + i, "mipmap", "com.yunkaweilai.android");
            Drawable drawable = getResources().getDrawable(id);
            anim.addFrame(drawable, 300);
        }
        anim.setOneShot(false);
        idImg.setBackgroundDrawable(anim);
        anim.start();

    }

}
